package com.jack.vipmis.vip.api.util;

import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 
 * @author JackLiang
 * @date 2014-7-7
 * @version 1.0
 */
public final class MsgUtil {

	public final static int	FAIL					= 0;

	public static final int	OK						= 1;
	/**
	 * 请求错误：执行请求发生异常
	 */
	public final static int	REQUEST_ERROR_EXCEPTION	= 2;

	/**
	 * 数据错误，请求成功，返回的数据不对
	 */
	public final static int	REQUEST_ERROR_DATA		= 11;

	/**
	 * 验证码错误
	 */
	public final static int	YZM_ERROR				= 21;
	/**
	 * 请求错误：服务器内部出错
	 */
	public final static int	REQUEST_ERROR_500		= 500;

	/**
	 * 返回消息
	 * 
	 * @param code
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> doneMsg(int code, Object obj) {
		Map<String, Object> dataMap = Maps.newHashMap();
		dataMap.put("data", obj);
		dataMap.put("msg", (code == OK) ? "操作成功！" : "操作失败！");
		dataMap.put("ret", code);
		return dataMap;
	}

	/**
	 * 返回
	 * 
	 * @param code
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> doneMsg(int code, String msg, Object obj) {
		Map<String, Object> dataMap = Maps.newHashMap();
		dataMap.put("data", obj);
		dataMap.put("msg", msg);
		dataMap.put("ret", code);
		return dataMap;
	}

	/**
	 * 操作成功
	 * 
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> doneOk(Object obj) {
		Map<String, Object> dataMap = Maps.newHashMap();
		dataMap.put("data", obj);
		dataMap.put("msg", "操纵成功！");
		dataMap.put("ret", MsgUtil.OK);
		return dataMap;
	}

	/**
	 * 操作失败
	 * 
	 * @param obj
	 * @return
	 */
	public static Map<String, Object> doneFail() {
		Map<String, Object> dataMap = Maps.newHashMap();
		dataMap.put("data", Lists.newArrayList());
		dataMap.put("msg", "请求发生异常！");
		dataMap.put("ret", MsgUtil.REQUEST_ERROR_EXCEPTION);
		return dataMap;
	}

}
